<?php

namespace Admin\Controller;
use Think\Controller;
class DataController extends Controller{

//
public function yaha(){
	
	//寻找所有数据
	$list = M('UserRelationship')->select();
	if(!empty($list)){
		$display_count = 0;
		foreach($list as $k=>$v){
			$string ='';
			$string_a = '';
			$display_count = $display_count+1;
			//获取上级层级id
			$string = $this->superior($v['user_id'],$v['user_id']);
			if(!empty($string)){
				$count   = count(explode(',',$string)); 
				$string_a .= $string.','.$v['subordinate_user'];
				$judge = M('UserRelationship')->where('id = %d',$v['id'])->save(array('level'=>$count+1,'scort'=>$string_a));
				if($judge === false){
					echo '失败了'.$v['id'];
					echo M()->_sql();die;
				}
			}
		}
		echo '更新了'.$display_count.'条';
	}
		
}

//寻找上级
public function superior($fans_id,$array_string=''){
	$result = M('UserRelationship')->where('subordinate_user = %d',$fans_id)->find();
	if(!empty($result)){
		$array_string = $this->superior($result['user_id'],$array_string =$result['user_id'].','.$array_string);
	}
	return $array_string;
}



	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	
	
	
	
	

 



	
	
	
	
	
}
